﻿<controls:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Manhua2.Pages.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Manhua2.Pages"
    xmlns:controls="using:Manhua2.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" FontFamily="Global User Interface">

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid x:Name="GridFull">
            <ProgressRing Margin="0,0,0,0" 
                          Width="50" 
                          Height="50" 
                          IsActive="{Binding Progress}"/>
            <ScrollViewer x:Name="scrollViewer" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.IsVerticalRailEnabled="False" ScrollViewer.IsVerticalScrollChainingEnabled="False"
                          Style="{StaticResource HorizontalScrollViewerStyle}" FontFamily="Global User Interface">
                <Grid>
                    <TextBlock Margin="30, 50, 0, 0" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Top" 
                               Grid.Column="1" 
                               IsHitTestVisible="false" 
                               Style="{StaticResource PageHeaderTextStyle}"
                               x:Uid="Histories"
                               Text="最近观看">
                    </TextBlock>
                    <TextBlock Margin="550, 50, 0, 0" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Top"                                
                               Grid.Column="1" 
                               IsHitTestVisible="false" 
                               Style="{StaticResource PageHeaderTextStyle}"
                               x:Uid="Latest"
                               Text="最新漫画" >
                    </TextBlock>
                    <WebView Margin="800,10,0,0" 
                             HorizontalAlignment="Left" 
                             VerticalAlignment="Top" 
                             Width="900" 
                             Height="120" 
                             Source="http://wowhy.sinaapp.com/metro.php"/>                    
                    <GridView Margin="30, 140, 0, 0"
                              ItemsSource="{Binding histories}"
                              ItemTemplate="{StaticResource ComicItemTemplate}"
                              SelectionMode="None"
                              IsSwipeEnabled="false"
                              IsItemClickEnabled="True"
                              ItemClick="ListView_ItemClick" >
                        <GridView.Template>
                            <ControlTemplate>
                                <Grid>
                                    <ItemsPresenter />
                                </Grid>
                            </ControlTemplate>
                        </GridView.Template>
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapGrid />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                    <GridView x:Name="itemGridView"
                              Margin="550, 140, 0, 0"
                              ItemsSource="{Binding comics}"
                              ItemTemplate="{StaticResource ComicItemTemplate}"
                              SelectionMode="None"
                              IsSwipeEnabled="false"
                              IsItemClickEnabled="True"
                              ItemClick="GridView_ItemClick">
                        <GridView.Template>
                            <ControlTemplate>
                                <Grid>
                                    <ItemsPresenter />
                                </Grid>
                            </ControlTemplate>
                        </GridView.Template>
                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapGrid />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
                </Grid>
            </ScrollViewer>
        </Grid>
        <Grid x:Name="GridSnapped" Visibility="Collapsed">
            <ProgressRing Margin="0,0,0,0" Width="100" Height="100" 
                          IsActive="{Binding Progress}"/>
            <ScrollViewer Style="{StaticResource VerticalScrollViewerStyle}">
                <StackPanel>
                    <TextBlock Margin="0, 20, 0, 0" 
                               Style="{StaticResource PageHeaderTextStyle}" 
                               x:Uid="Histories"
                               Text="最近观看" />
                    <ListView Margin="0, 20, 0, 0"
                              ItemsSource="{Binding histories}"
                              ItemTemplate="{StaticResource ComicItemSnappedTemplate}"
                              SelectionMode="None"
                              IsSwipeEnabled="false"
                              IsItemClickEnabled="True"
                              ItemClick="ListView_ItemClick">
                        <ListView.Template>
                            <ControlTemplate>
                                <Grid>
                                    <ItemsPresenter />
                                </Grid>
                            </ControlTemplate>
                        </ListView.Template>
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel />
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                    </ListView>
                    <TextBlock Margin="0, 20, 0, 0" 
                               Style="{StaticResource PageHeaderTextStyle}"                                
                               x:Uid="Latest"
                               Text="最新更新" />
                    <ListView Margin="0, 20, 0, 0"
                              ItemsSource="{Binding comics}"
                              ItemTemplate="{StaticResource ComicItemSnappedTemplate}"
                              SelectionMode="None"
                              IsSwipeEnabled="False"
                              IsItemClickEnabled="True"
                              ItemClick="GridView_ItemClick">
                        <ListView.Template>
                            <ControlTemplate>
                                <Grid>
                                    <ItemsPresenter />
                                </Grid>
                            </ControlTemplate>
                        </ListView.Template>
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel />
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                    </ListView>
                </StackPanel>
            </ScrollViewer>
        </Grid>
        
        
        <!-- 管理视图状态 -->
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait" />
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridFull" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridSnapped" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
    
    <controls:LayoutAwarePage.BottomAppBar>
        <AppBar>
            <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
                <Button x:Name="btnRefresh" 
                        Style="{StaticResource RefreshAppBarButtonStyle}"
                        IsEnabled="{Binding IsBtnEnabled}"
                        Click="btnRefresh_Click" 
                        x:Uid="btnRefresh"
                        AutomationProperties.Name="刷新"/>
                <Button x:Name="btnOpen" 
                        Style="{StaticResource BrowsePhotosAppBarButtonStyle}"                        
                        Click="btnOpen_Click" 
                        x:Uid="btnOpen"
                        AutomationProperties.Name="本地漫画" />
                <Button x:Name="btnDownload" 
                        Style="{StaticResource DownloadAppBarButtonStyle}"                        
                        Click="btnDownload_Click"
                        AutomationProperties.Name="正在下载" />
                <Button x:Name="btnFavorite" Style="{StaticResource FavoriteAppBarButtonStyle}"
                        AutomationProperties.Name="收藏" Click="btnFavorite_Click" />
                <Button x:Name="btnHelp" Style="{StaticResource HelpAppBarButtonStyle}"
                            AutomationProperties.Name="帮助" Click="btnHelp_Click"/>
            </StackPanel>
        </AppBar>
    </controls:LayoutAwarePage.BottomAppBar>
</controls:LayoutAwarePage>
